//
//  KWLEditLaywerViewController.m
//  KWNLaywerClient
//
//  Created by 张明磊 on 14/11/10.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "KWLEditLaywerViewController.h"
#import "Model_lawyerInfo.h"
#import "UIButton+WebCache.h"
#import "KWLEditIntroViewController.h"
#import "KWNNetwork.h"
#import "Model_user.h"
#import <AVFoundation/AVFoundation.h>
#include<AssetsLibrary/AssetsLibrary.h>
#import "UIImageView+WebCache.h"
#import "KWLLoginViewController.h"
@interface KWLEditLaywerViewController ()<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property (strong, nonatomic) Model_lawyerInfo *model_info;

@property (weak, nonatomic) UILabel *label_sign;
@property (weak, nonatomic) UILabel *label_intro;
@property (strong, nonatomic) UILabel *label_name;

@property (weak, nonatomic) UIImageView *imageView_portrait;

@end

@implementation KWLEditLaywerViewController

- (id)initWithModel:(Model_lawyerInfo *)model_lawyer{
    self = [super init];
    if(self){
        _model_info = model_lawyer;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self UI_editTitle];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated{
    BOOL reload = [Model_user sharedInstance].bool_isLoadLawyer;
    if(reload){
        [[KWNNetwork sharedInstance] lawyer_getLawyerInformationFinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
            switch (stateCode) {
                case 10000:{
                    Model_lawyerInfo *info = result[0];
                    _model_info = info;
                    [Model_user sharedInstance].bool_isLoadLawyer = NO;
                    _label_intro.text = info.string_intro;
                    _label_sign.text = info.string_signatu;
                    _label_name.text = _model_info.string_realname;
                    [_imageView_portrait sd_setImageWithURL:[NSURL URLWithString:info.string_portrait] placeholderImage:[UIImage imageFileName:Default_portrait]];
                }break;
                case 10003:
                {
                    [self editLaywerTokenIsFailure];
                    
                }
                    break;
                default:
                    break;
            }
        }];
    }
}

- (void)UI_editTitle{
    self.view.backgroundColor = RGB(239, 239, 244);
    
    UIView *imageView_title = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44 + IOS7_SIZE)];
    imageView_title.backgroundColor = RGB(91, 165, 229);
    [self.view addSubview:imageView_title];

    UIButton *button_menu = [UIButton buttonWithType:UIButtonTypeCustom];
    button_menu.frame = CGRectMake(0, IOS7_SIZE, 60, 45);
    [button_menu setImage:[UIImage imageFileName:@"button_back.png"] forState:UIControlStateNormal];
    [button_menu addTarget:self action:@selector(didClickButton_edit:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_menu];
    button_menu.tag = 100;
    
    UILabel *label_title = [[UILabel alloc] initWithFrame:CGRectMake(imageView_title.frame.origin.x,IOS7_SIZE + 5,imageView_title.frame.size.width,35)];
    label_title.backgroundColor = [UIColor clearColor];
    label_title.textColor = ColorOfTitle;
    label_title.textAlignment = NSTextAlignmentCenter;
    label_title.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0f];
    [self.view addSubview:label_title];
    label_title.text = @"编辑个人资料";
    
    UIButton *button_one = [UIButton buttonWithType:UIButtonTypeCustom];
    button_one.frame = CGRectMake(0, imageView_title.frame.origin.y + imageView_title.frame.size.height + 20, 320, 67);
    button_one.backgroundColor = [UIColor clearColor];
    [button_one setImage:[UIImage imageFileName:@"edit_one.png"] forState:UIControlStateNormal];
    [button_one addTarget:self action:@selector(didClickButton_edit:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_one];
    button_one.tag = 101;
    
    UIImageView *imageView_portrait = [[UIImageView alloc] initWithFrame:CGRectMake(220, button_one.frame.origin.y + 5, 55, 55)];
    [imageView_portrait setContentMode:UIViewContentModeScaleAspectFill];
    [self.view addSubview:imageView_portrait];
    imageView_portrait.layer.masksToBounds = YES;
    imageView_portrait.layer.cornerRadius = 27.0;
    imageView_portrait.layer.borderWidth = 1.0;//边框宽度
    imageView_portrait.layer.borderColor = RGB(228, 228, 228).CGColor;//边框颜色
    [imageView_portrait sd_setImageWithURL:[NSURL URLWithString:_model_info.string_portrait] placeholderImage:[UIImage imageFileName:Default_portrait]];
    _imageView_portrait = imageView_portrait;
    
    UIButton *button_two = [UIButton buttonWithType:UIButtonTypeCustom];
    button_two.frame = CGRectMake(0, button_one.frame.origin.y + button_one.frame.size.height - 2, 320, 44);
    button_two.backgroundColor = [UIColor clearColor];
    [button_two setImage:[UIImage imageFileName:@"edit_two.png"] forState:UIControlStateNormal];
    [button_two addTarget:self action:@selector(didClickButton_edit:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_two];
    button_two.tag = 102;
    
    _label_name = [[UILabel alloc] initWithFrame:CGRectMake(_imageView_portrait.frame.origin.x, button_two.frame.origin.y + 8, 60, 30)];
    _label_name.backgroundColor = [UIColor clearColor];
    _label_name.text = _model_info.string_realname;
    _label_name.textColor = RGB(217,217,217);
    _label_name.textAlignment = NSTextAlignmentRight;
    _label_name.font = [UIFont fontWithName:@"Helvetica" size:15.0f];
    [self.view addSubview:_label_name];
    
    UIButton *button_three = [UIButton buttonWithType:UIButtonTypeCustom];
    button_three.frame = CGRectMake(0, button_two.frame.origin.y + button_two.frame.size.height, 320, 44);
    button_three.backgroundColor = [UIColor clearColor];
    [button_three setImage:[UIImage imageFileName:@"edit_three.png"] forState:UIControlStateNormal];
    [button_three addTarget:self action:@selector(didClickButton_edit:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_three];
    button_three.tag = 103;
    
    UILabel *label_qianming = [[UILabel alloc] initWithFrame:CGRectMake(100, button_three.frame.origin.y + 7, 180, 30)];
    label_qianming.backgroundColor = [UIColor clearColor];
    label_qianming.text = _model_info.string_signatu;
    label_qianming.textColor = RGB(198,198,198);
    label_qianming.textAlignment = NSTextAlignmentRight;
    label_qianming.font = [UIFont fontWithName:@"Helvetica" size:15.0f];
    [self.view addSubview:label_qianming];
    _label_sign = label_qianming;
    
    UIButton *button_four = [UIButton buttonWithType:UIButtonTypeCustom];
    button_four.frame = CGRectMake(0, button_three.frame.origin.y + button_three.frame.size.height, 320, 86);
    button_four.backgroundColor = [UIColor clearColor];
    [button_four setImage:[UIImage imageFileName:@"edit_four.png"] forState:UIControlStateNormal];
    [button_four addTarget:self action:@selector(didClickButton_edit:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_four];
    button_four.tag = 104;
    
    UILabel *label_jieshao = [[UILabel alloc] initWithFrame:CGRectMake(label_qianming.frame.origin.x, button_four.frame.origin.y + 10, 180, 60)];
    label_jieshao.backgroundColor = [UIColor clearColor];
    label_jieshao.text = _model_info.string_intro;
    label_jieshao.textColor = RGB(198,198,198);
    label_jieshao.numberOfLines = 3;
    label_jieshao.textAlignment = NSTextAlignmentRight;
    label_jieshao.font = [UIFont fontWithName:@"Helvetica" size:15.0f];
    [self.view addSubview:label_jieshao];
    _label_intro = label_jieshao;
}

- (void)didClickButton_edit:(UIButton *)button{
    switch (button.tag) {
        case 99:{
            
        }break;
        case 100:{
            [self popViewController];
        }break;
        case 101:{
            UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"使用相机拍摄",@"从相册中选择", nil];
            [sheet showInView:self.view];
        }break;
        case 102:{
            
        }break;
        case 103:{
            KWLEditIntroViewController *controller_intro = [[KWLEditIntroViewController alloc] initWithTag:0 andString:_model_info.string_signatu];
            [self pushViewController:controller_intro];
        }break;
        case 104:{
            KWLEditIntroViewController *controller_intro = [[KWLEditIntroViewController alloc] initWithTag:1 andString:_model_info.string_intro];
            [self pushViewController:controller_intro];
        }break;
        default:
            break;
    }
}


#pragma mark - 点击上传图片 -
/**
 *  点击上传图片
 */
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:{
            if(IOS7_SIZE){
                AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
                switch (authStatus) {
                    case AVAuthorizationStatusNotDetermined:{
                        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                            if(granted){
// CS 快法务 KLW 2014-12-24
//                                [UIUtils showHUD:@"启动中..." afterTime:99];
//                                
                                [SVProgressHUD showWithStatus:@"启动中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
                                [self.view endEditing:YES];
                                double delayInSeconds = 0.2;
                                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                                    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                                    {
                                        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
                                        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
                                        [imagePicker setToolbarHidden:YES];
                                        //[imagePicker.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
                                        [imagePicker setDelegate:self];
                                        //[imagePicker setAllowsEditing:YES];
                                        //显示Camera VC
                                        [self presentViewController:imagePicker animated:YES completion:^(){
// CS 快法务 KLW 2014-12-24
//                                            [UIUtils dismissCurrentHUD];
//                                            
                                            [SVProgressHUD dismiss];
// CE 快法务 KLW 2014-12-24
                                            //[self swapFrontAndBackCameras];
                                        }];
                                    }
// AS 快法务 KLW 2014-12-24
                                    else
                                    {
                                        [SVProgressHUD dismiss];
                                    }
// AE 快法务 KLW 2014-12-24
                                });
                            }
                            else {
                                if(IOS8_VERSION){
                                    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                                    NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                                    NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-相机\"允许\"%@\"访问您的相机",appName];
                                    UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"提示" message:string_content delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"设置",nil];
                                    [alter_camera show];
                                    alter_camera.tag = 100;
                                    
                                }
                                else{
                                    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                                    NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                                    NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-相机\"允许\"%@\"访问您的相机",appName];
                                    UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"" message:string_content delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                                    [alter_camera show];
                                }
                            }
                        }];
                    }
                    case AVAuthorizationStatusRestricted:{
                        if(IOS8_VERSION){
                            NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                            NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                            NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-相机\"允许\"%@\"访问您的相机",appName];
                            UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"提示" message:string_content delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"设置",nil];
                            [alter_camera show];
                            alter_camera.tag = 100;
                            
                        }
                        else{
                            NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                            NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                            NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-相机\"允许\"%@\"访问您的相机",appName];
                            UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"" message:string_content delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                            [alter_camera show];
                        }
                    }break;
                    case AVAuthorizationStatusDenied:{
                        if(IOS8_VERSION){
                            NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                            NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                            NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-相机\"允许\"%@\"访问您的相机",appName];
                            UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"提示" message:string_content delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"设置",nil];
                            [alter_camera show];
                            alter_camera.tag = 100;
                        }
                        else{
                            NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                            NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                            NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-相机\"允许\"%@\"访问您的相机",appName];
                            UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"" message:string_content delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                            [alter_camera show];
                        }
                    }break;
                    case AVAuthorizationStatusAuthorized:{
// CS 快法务 KLW 2014-12-24
//                        [UIUtils showHUD:@"启动中..." afterTime:99];
//                        
                        [SVProgressHUD showWithStatus:@"启动中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
                        [self.view endEditing:YES];
                        double delayInSeconds = 0.2;
                        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                            {
                                UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
                                [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
                                [imagePicker setToolbarHidden:YES];
                                //[imagePicker.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
                                [imagePicker setDelegate:self];
                                //[imagePicker setAllowsEditing:YES];
                                //显示Camera VC
                                [self presentViewController:imagePicker animated:YES completion:^(){
// CS 快法务 KLW 2014-12-24
//                                    [UIUtils dismissCurrentHUD];
//                                    
                                    [SVProgressHUD dismiss];
// CE 快法务 KLW 2014-12-24
                                    //[self swapFrontAndBackCameras];
                                }];
                            }
// AS 快法务 KLW 2014-12-24
                            else
                            {
                                [SVProgressHUD dismiss];
                            }
// AE 快法务 KLW 2014-12-24
                        });
                    }break;
                    default:
                        break;
                }
            }else{
// CS 快法务 KLW 2014-12-24
//                [UIUtils showHUD:@"启动中..." afterTime:99];
//                
                [SVProgressHUD showWithStatus:@"启动中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
                [self.view endEditing:YES];
                double delayInSeconds = 0.2;
                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                    {
                        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
                        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
                        [imagePicker setToolbarHidden:YES];
                        //[imagePicker.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
                        [imagePicker setDelegate:self];
                        //[imagePicker setAllowsEditing:YES];
                        //显示Camera VC
                        [self presentViewController:imagePicker animated:YES completion:^(){
// CS 快法务 KLW 2014-12-24
//                            [UIUtils dismissCurrentHUD];
//                            
                            [SVProgressHUD dismiss];
// CE 快法务 KLW 2014-12-24
                            //[self swapFrontAndBackCameras];
                        }];
                    }
// AS 快法务 KLW 2014-12-24
                    else
                    {
                        [SVProgressHUD dismiss];
                    }
// AE 快法务 KLW 2014-12-24
                });
                
            }
        }break;
        case 1:{
            /**
             *  从相册选择
             */
            ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
            switch (author) {
                case ALAuthorizationStatusNotDetermined:{
                    ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
                    [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                        if (*stop) {
                            //点击“好”回调方法:这里是重点
// CS 快法务 KLW 2014-12-24
//                            [UIUtils showHUD:@"启动中..." afterTime:99];
//                            
                            [SVProgressHUD showWithStatus:@"启动中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
                            [self.view endEditing:YES];
                            double delayInSeconds = 0.2;
                            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                                if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
                                {
                                    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
                                    [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
                                    [imagePicker setToolbarHidden:YES];
                                    //[imagePicker.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
                                    [imagePicker setDelegate:self];
                                    //[imagePicker setAllowsEditing:YES];
                                    //显示Camera VC
                                    [self presentViewController:imagePicker animated:YES completion:^(){
// CS 快法务 KLW 2014-12-24
//                                        [UIUtils dismissCurrentHUD];
//                                        
                                        [SVProgressHUD dismiss];
// CE 快法务 KLW 2014-12-24
                                        //[self swapFrontAndBackCameras];
                                    }];
                                }
// AS 快法务 KLW 2014-12-24
                                else
                                {
                                    [SVProgressHUD dismiss];
                                }
// AE 快法务 KLW 2014-12-24
                            });
                            return;
                        }
                        *stop = TRUE;
                    } failureBlock:^(NSError *error) {
                        if(IOS8_VERSION){
                            NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                            NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                            NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-照片\"允许\"%@\"访问您的相机",appName];
                            UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"提示" message:string_content delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"设置",nil];
                            [alter_camera show];
                            alter_camera.tag = 100;
                            
                        }
                        else{
                            NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                            NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                            NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-照片\"允许\"%@\"访问您的相机",appName];
                            UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"" message:string_content delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                            [alter_camera show];
                        }
                        [self dismissViewControllerAnimated:YES completion:nil];
                    }];
                }break;
                case ALAuthorizationStatusRestricted:{
                    if(IOS8_VERSION){
                        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                        NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                        NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-照片\"允许\"%@\"访问您的相机",appName];
                        UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"提示" message:string_content delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"设置",nil];
                        [alter_camera show];
                        alter_camera.tag = 100;
                        
                    }
                    else{
                        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                        NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                        NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-照片\"允许\"%@\"访问您的相机",appName];
                        UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"" message:string_content delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        [alter_camera show];
                    }
                }break;
                case ALAuthorizationStatusDenied:{
                    if(IOS8_VERSION){
                        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                        NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                        NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-照片\"允许\"%@\"访问您的相机",appName];
                        UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"提示" message:string_content delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"设置",nil];
                        [alter_camera show];
                        alter_camera.tag = 100;
                        
                    }
                    else{
                        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
                        NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
                        NSString *string_content = [NSString stringWithFormat:@"请在\"设置-隐私-照片\"允许\"%@\"访问您的相机",appName];
                        UIAlertView *alter_camera = [[UIAlertView alloc] initWithTitle:@"" message:string_content delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        [alter_camera show];
                    }
                }break;
                case ALAuthorizationStatusAuthorized:{
                    [SVProgressHUD showWithStatus:@"启动中..." maskType:SVProgressHUDMaskTypeClear];
                    [self.view endEditing:YES];
                    double delayInSeconds = 0.2;
                    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
                        {
                            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
                            [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
                            [imagePicker setToolbarHidden:NO];
                            //[imagePicker.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
                            imagePicker.delegate = self;
                            //[imagePicker setAllowsEditing:NO];
                            //显示Camera VC
                            [self presentViewController:imagePicker animated:YES completion:^(){
                                [SVProgressHUD dismiss];
                            }];
                        }
                        else
                        {
                            [SVProgressHUD dismiss];
                        }
                    });
                }break;
                default:
                    break;
            }
        }break;
        case 2:{
            
        }break;
        default:
            break;
    }
}

#pragma mark - ios8打开系统设置 -
/**
 *  ios8打开系统设置
 */
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (alertView.tag) {
        case 100:{
            if (buttonIndex == 1) {
                // Send the user to the Settings for this app
                NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
                [[UIApplication sharedApplication] openURL:settingsURL];
            }
        }break;
        case 101:{
            
        }break;
            //账号替换
        case 10003:{
            KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
            [self pushViewController:login];
        }break;

        default:
            break;
    }
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark - 照相后回调 -
/**
 *  照相后回调
 */
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //得到图片
    UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
    image = [UIUtils imageWithImageSimple:image scaledToSize:CGSizeMake(360, 480)];
    NSString *string_name = [[UIUtils getCurrentDateString] stringByAppendingString:@".png"];
    NSString *string_path = [UIUtils saveImage:image WithName:string_name];
    [[KWNNetwork sharedInstance] edit_laywerPortrait:string_path FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
        switch (stateCode) {
            case 10000:{
                [[KWNNetwork sharedInstance] lawyer_getLawyerInformationFinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
                    switch (stateCode) {
                        case 10000:{
                            UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"上传成功" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                            [alterView show];
                            
                            Model_lawyerInfo *info = result[0];
                            _model_info = info;
                            [_imageView_portrait sd_setImageWithURL:[NSURL URLWithString:info.string_portrait] placeholderImage:[UIImage imageFileName:Default_portrait]];
                            
                            [Model_user sharedInstance].bool_isLoadLawyer = YES;
                        }break;
                        case 10003:
                        {
                            [self editLaywerTokenIsFailure];
//                            NSString *string_msg  = result[0];
//                            [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                            double delayInSeconds = 1.5;
//                            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//                            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//                                //code to be executed on the main queue after delay
//                                KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
//                                [self pushViewController:login];
//                            });
                        }break;
                        default:{
                            NSString *string_message = result[0];
// CS 快法务 KLW 2014-12-24
//                            [UIUtils view_showProgressHUD:string_message inView:self.view withTime:1.5f];
//                            
                            [SVProgressHUD showErrorWithStatus:string_message duration:1.5];
// CE 快法务 KLW 2014-12-24
                        }break;
                    }
                }];
            }break;
                
            default:
                break;
        }
    }];
     
    [picker dismissViewControllerAnimated:YES completion:^{
            
    }];
}


#pragma mark - 账号被替换下线提示 -
- (void)editLaywerTokenIsFailure{
    UIAlertView *alter_login;
    if(IOS8_VERSION){
        alter_login = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    else{
        alter_login = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    }
    alter_login.tag = 10003;
    [alter_login show];
}

@end
